#include <stdio.h>

char num[20];
int n; int sum;

int main() {
	scanf("%d", &n);

	while (n--) {
		sum = 0;

		for (int i=0; i<16; i++)
			scanf(" %c", &num[i]);

		for (int i=0; i<16; i++) {
			int temp = num[i]-'0';
			
			if (i%2!=0)
				sum+= temp;
			else {
				temp*=2;

				while (temp!=0) {
					sum+= (temp%10);
					temp/=10;
				}
			}
		}

		if (sum%10==0)
			printf("Valid\n");
		else
			printf("Invalid\n"); 
	}
}
